<?php 
include_once("rm_conexion.class.php");

class Comentario{
 //constructor	
 var $con;
 function Comentario(){
 	$this->con=new DBManager;
 }
 
 function listado_ultimos($limite){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM comentarios ORDER BY fecha DESC LIMIT $limite");
	 return $result;
   }
 }

 /*function listado_paginado($RegistrosAEmpezar, $RegistrosAMostrar){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM articulos ORDER BY id DESC LIMIT $RegistrosAEmpezar, $RegistrosAMostrar");
	 return $result;
   }
 }*/
 
 function numero_por_articulo($articulo){
   if($this->con->conectar()==true){
     $result = @mysql_num_rows(mysql_query("SELECT * FROM comentarios WHERE articulo_id=$articulo"));
	 return $result;
   }
 }

 function insertar($articulo_id, $nombre, $contenido, $mail, $web){
   if($this->con->conectar()==true){
     $result = @mysql_query("INSERT INTO comentarios (articulo_id, nombre, fecha, contenido, mail, web) VALUES ($articulo_id, '$nombre', NOW(), '$contenido', '$mail', '$web')");
     return $result;
   }
 }

 function actualizar($id){
   if($this->con->conectar()==true) {
     $result = @mysql_query("UPDATE comentarios SET WHERE id=$id");
     return $result;
   }
 }

 function eliminar($id){
   if($this->con->conectar()==true){
     $result = @mysql_query("DELETE FROM comentarios WHERE id=$id");
     return $result;
   }
 }
 
 function mostrar($id){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM comentarios WHERE id=$id");
     return $result;
   }
 }

 function listado_por_articulo($articulo_id,$orden='ASC'){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM comentarios WHERE articulo_id=$articulo_id ORDER BY fecha $orden");
	 return $result;
   }
 }
 function listado_por_pagina($articulo_id, $regAEmp, $regAMost, $orden){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM comentarios WHERE articulo_id=$articulo_id ORDER BY fecha $orden LIMIT $regAEmp, $regAMost");
	 return $result;
   }
 }
 //verificar
 function busqueda($campo, $valor){
   if($this->con->conectar()==true){
     $result = @mysql_query("SELECT * FROM articulos WHERE $campo='$valor'");
	 return $result;
   }
 }
}
?>
